package com.cwvs.cat.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cwvs.cat.R;
import com.cwvs.cat.bean.MsgClub;
import com.cwvs.cat.net.Port;

public class MsgClubAdapter  extends BaseAdapter {

	private List<MsgClub> list_contact;
	private LayoutInflater inflater;
	FinalBitmap fb; 
	public MsgClubAdapter() {
		// TODO Auto-generated constructor stub
	}

	public MsgClubAdapter(Activity ac, List<MsgClub> list) {
		// TODO Auto-generated constructor stub
		this.inflater = LayoutInflater.from(ac);
		this.list_contact = list;
		fb = FinalBitmap.create(ac);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list_contact.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list_contact.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.item_list_msg_club, null);
			viewholder = new ViewHolder();
			viewholder.txt_club_message_name=(TextView) convertView.findViewById(R.id.txt_club_message_name);
			viewholder.msgclub_time=(TextView) convertView.findViewById(R.id.msgclub_time);
			viewholder.msgClub_image=(ImageView) convertView.findViewById(R.id.msgClub_image);
			convertView.setTag(viewholder);
		}else{
			viewholder = (ViewHolder) convertView.getTag();
		}
		viewholder.txt_club_message_name.setText(list_contact.get(position).title);
		viewholder.msgclub_time.setText(list_contact.get(position).created);
		if (!list_contact.get(position).avatar.equals("null")&&!list_contact.get(position).avatar.equals("")) {
			if (list_contact.get(position).avatar.contains("http")) {
				fb.display(viewholder.msgClub_image,list_contact.get(position).avatar);
			}else {
				fb.display(viewholder.msgClub_image,Port.getImg+list_contact.get(position).avatar);
			}
		}
		return convertView;
	}

	class ViewHolder {
		TextView txt_club_message_name,msgclub_time;
		ImageView msgClub_image;
	}

}
